package com.wenyl.juc.thread.CycliBarrierTest;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author Swimming Dragon
 * @description: TODO
 * @date 2024年11月07日 11:00
 */
public class UserRun1 implements Runnable{

    private String name;
    private TimeCount tc;
    private CyclicBarrier cb;
    public UserRun1(String name,TimeCount tc,CyclicBarrier cb){
        this.name = name;
        this.tc = tc;
        this.cb = cb;
    }
    @Override
    public void run() {
        if(name.equals("爬虫功能")){
            try {
                Thread.sleep(4000);
                tc.setCount1(4000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        else if(name.equals("发送邮件")){
            try {
                Thread.sleep(8000);
                tc.setCount2(8000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        try {
            this.cb.await();
        } catch (InterruptedException | BrokenBarrierException e) {
            throw new RuntimeException(e);
        }
        System.out.println("-----"+name+",end-----");
    }
}
